package com.meixiang.adapter.service;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.entity.services.ClassOneBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：黑哥 on 2016/7/13 17:13
 * list_item_subjects
 */
public class SubjectsAdapter extends RecyclerView.Adapter<SubjectsAdapter.ViewHolder> {


    private List<ClassOneBean> mList = new ArrayList<>();
    private Context context;


    public SubjectsAdapter(Context context) {
        this.context = context;

    }


    public void addAll(List<ClassOneBean> mList) {
        this.mList.addAll(mList);
        this.notifyDataSetChanged();
    }

    public void clear() {
        this.mList.clear();
        this.notifyDataSetChanged();
    }

    public List<ClassOneBean> getData() {
        return mList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_subjects, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        if (mListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mListener.onItemClick(holder.itemView, pos);
                    //选中时改变颜色

                }
            });
        }
        holder.mTvContent.setText(mList.get(position).getGcName());
    }

    /**
     * 单击事件监听器
     */
    private onItemClickListener mListener = null;

    public void setOnItemClickListener(onItemClickListener listener) {
        mListener = listener;
    }

    public interface onItemClickListener {


        void onItemClick(View v, int position);

    }

    @Override
    public int getItemCount() {
        Log.e("TAG","输出item条目="+mList.size());
        return mList.size();

    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_content)
        TextView mTvContent;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
